<template>
	<view class="waterfall-item-container">
		<view class="waterfall-item">
			<view class="image">
				<image class="image" @tap="onTap" :src="params.picList[0]" :style="{ height: `${h}px` }"
					mode="aspectFill" @load="emitHeight" @error="emitHeight">
					<!-- 	<image class="image" @tap="onTap" :src="params.object[0].result" mode="widthFix" @load="emitHeight"
					@error="emitHeight"> -->
				</image>
				<text class="text" v-show="params.type == 0">景点</text>
				<text class="text" v-show="params.type == 1"> 美食</text>
				<text class="text" v-show="params.type == 2"> 住宿</text>
			</view>
			<view class="content">
				<view class="content-title">{{params.title}}</view>
				<view class="content-user">
					<view class="content-user-list">
						<image class="images" :src="params.headUrl" mode="">

						</image>
						<view class="content-user-name">
							{{params.publisherName}}
						</view>
					</view>
					<view class="content-user-praise">
						<u-icon name="eye"></u-icon>
						<text class="image">{{params.viewCount}}</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "helangWaterfallItem",
		options: {
			virtualHost: true
		},
		props: {
			params: {
				type: Object,
				default () {
					return {}
				}
			},
			tag: {
				type: String | Number,
				default: ''
			},
			index: {
				type: Number,
				default: -1
			}
		},
		data() {
			return {
				likenumShow: true,
				h: 0
			};
		},
		mounted() {
			this.h = this.params.hlist[0]
		},

		methods: {
			// 点赞
			like(obj) {
				let list = {
					id: obj.id,
					type: obj.publisherType
				}

				this.$api.get('/api/introdution/Like', list)
					.then(res => {
						// this.getList(this.id)
						this.$showToast(res.data.data)
						if (res.data.data == '点赞成功') {
							this.likenumShow = false

						} else if (res.data.data == '取消成功') {
							this.likenumShow = true
						}
					})
			},

			// 发出组件高度信息，在此处可以区分正确和错误的加载，给予错误的提示图片
			emitHeight(e) {
				const query = uni.createSelectorQuery().in(this);
				query.select('.waterfall-item-container').boundingClientRect(data => {
					let height = Math.floor(data.height);

					this.$emit("height", height, this.$props.tag);

				}).exec();
			},
			onTap() {
				uni.navigateTo({
					url: '/pages/index/waterfall/details?id=' + this.$props.params.id
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.waterfall-item {
		// padding: 4rpx;
		margin: 2rpx;
		background-color: #fff;
		border-radius: 16rpx;
		font-size: 28rpx;
		color: #666;
		overflow: auto;
		// box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2);

		.image {
			// 默认设置一个图片的大约值
			// height: 100%;
			border-radius: 16rpx 16rpx 0 0;
			display: block;
			width: 100%;
			position: relative;

			// 默认设置一个图片的大约值
			// height: 100%;
			.text {
				position: absolute;
				top: 0;
				left: 0;
				font-size: 22rpx;
				color: #ffffff;
				// background: #ff7d01;
				// background-color: argb(0, 0, 0, 0.5);
				// background: argb(0, 0, 0, 0.5);
				background: rgba(0, 0, 0, 0.5);

				border-radius: 16rpx 0 18rpx 0;
				padding: 4rpx 6rpx;
			}
		}

		.content {
			padding: 16rpx;
			// margin-top: 16rpx;

			.content-title {
				display: -webkit-box;
				-webkit-line-clamp: 2;
				/* 指定最大行数 */
				-webkit-box-orient: vertical;
				/* 垂直排列文本 */
				overflow: hidden;

				font-size: 28rpx !important;
				color: #333 !important;
			}

			.content-user {
				display: flex;
				justify-content: space-between;
				margin: 8rpx 0;

				.content-user-list {
					display: flex;
					align-items: center;

					.images {
						border-radius: 30rpx;
						width: 40rpx;
						height: 40rpx;
					}

					.content-user-name {
						width: 190rpx;
						// margin: 0 10rpx;
						font-size: 24rpx;
						color: #777777;
						display: -webkit-box;
						-webkit-line-clamp: 1;
						/* 指定最大行数 */
						-webkit-box-orient: vertical;
						/* 垂直排列文本 */
						overflow: hidden;
					}
				}

				.content-user-praise {
					display: flex;
					align-items: center;

					.image {
						// border-radius: 15px;
						margin-left: 4rpx;
					}
				}
			}

		}
	}
</style>